#ifndef FILESYS_CACHE_H
#define FILESYS_CACHE_H

#include "lib/kernel/bitmap.h"
#include "threads/synch.h"
#include "devices/disk.h"

#define CACHE_SIZE_LIMIT 64

struct bitmap* cache_bitmap;
struct cache_disk_sector* cache_list[CACHE_SIZE_LIMIT];
int cache_victim_idx;
struct lock cache_lock;

struct cache_disk_sector
{
    disk_sector_t cache_sec_idx;
    bool cache_dirty;
    bool cache_access_bit;
    void* cache_buffer;
};

void cache_init (void);
void cache_list_init (void);
struct cache_disk_sector* cache_initialize_sector (void);
void cache_read_sector (disk_sector_t, void*, int, int);
void cache_write_sector (disk_sector_t, void*, int, int);
void cache_read_or_write_sector (disk_sector_t, void*, int, int, bool);
void cache_write_back_sector (int);
void cache_flush_sector (void);
void cache_select_victim (void);
size_t cache_create_sector (disk_sector_t);
int cache_find_sector (disk_sector_t);
void cache_write_behind_sector (void);
void cache_write_behind (void);

#endif /* FILESYS_CACHE_H */

